package cn.tedu.egnotice1113.base.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Lombok提供的注解:
 * 1.@Setter注解:
 *
 *
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    //状态码,提示消息,具体数据
    //{"state":10100,"message":"登录成功","data":null}

    private Integer state;
    private String message;
    private Object data;

    /**
     * 1.构造方法1:针对于没有数据返回的控制器方法,比如:登录,注册,添加资讯;
     */
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    /**
     * 2.
     */
    public JsonResult(StatusCode statusCode, Object data){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    /**
     * 3.静态方法1:针对于没有数据返回的操作成功的控制器方法;
     * 控制器方法:return JsonResult.ok();
     */



    public static JsonResult ok(Object data){
       return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    /**
     *4.静态方法2:针对于有具体数据返回的操作成功的控制器方法;
     * 控制器方法:return jsonResult.ok(noticeListVOS);
     */
    public static JsonResult ok(){
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }
}
